<?php
session_start();
require "../../../global.php";//$dirname."/".
require RootDir."/"."inc/config.php";
require RootDir."/"."inc/Uifunction.php";
require RootDir."/".$SystemConest[1]."/UIFunction/adminClass.php";
require RootDir."/".$SystemConest[1]."/system/Config.php";
require RootDir."/".$SystemConest[1]."/system/menusys/function.php";
require RootDir."/".$SystemConest[1]."/system/classsys/function.php";
require "function.php";
require "AdminSysClass.php";

$mydb=new YYBDB();
$TableName=reTableName($mydb,$MenuId);
CheckRule($MenuId,$mydb,$TableName,"");//检查登陆权限


$Cmd=$_REQUEST["Cmd"];
$CurrMenuId=$_REQUEST["CurrMenuId"];
$AdminFields=array();

//添加用户
$MyAdminSys=new AdminSys();
$MyAdminSys->TableName=$TableName;
if($Cmd=="Add")
{
	CheckRule($MenuId,$mydb,$TableName,"Add");//检查增加权限
   if(mb_strlen($_REQUEST[$TableName."1"])>4)
   {
   		$AdminFields[1]=$_REQUEST[$TableName."1"];
		if($_REQUEST[$TableName."2"]!="") $AdminFields[2]=md5($_REQUEST[$TableName."2"]);
		$AdminFields[3]=$_REQUEST[$TableName."3"];
		$AdminFields[4]=$_REQUEST[$TableName."4"];
		$AdminFields[5]=$_REQUEST[$TableName."5"];
		$AdminFields[7]=$_REQUEST[$TableName."7"];
		$MyAdminSys->UserName=$_REQUEST[$TableName."1"];
		$MyAdminSys->Info=$AdminFields;
		$MyAdminSys->TableName=$TableName;
		if($MyAdminSys->Reg()==1)
		{
			$msg="用户名重复！";
		}
		else
		{
			$msg="";
		}
   }
   else
   {
   	 $msg="　　用户名不能少于5位！";
   }
   gourl("?MenuId=".$_REQUEST["MenuId"]."&Msg=".$msg,1);
   
}

//删除用户

if( $Cmd=="Del")
{
		
	   CheckRule($MenuId,$mydb,$TableName,"Del");//检查增加权限
	   $CurrMenuId=$_REQUEST["CurrMenuId"];
	   if(strlen($CurrMenuId)>0)
	   {
	  	
		    //删除用户的所有权限
		   AllRuleSave($mydb,$CurrMenuId,"Delete");
		   $mydb->TableName=$TableName;
		   $AdminFields[0]=$CurrMenuId;
           $mydb->ArrFields=$AdminFields;
		    
           $mydb->Delete();
           $msg="　　用户名删除成功！";
		}
		 gourl("?MenuId=".$_REQUEST["MenuId"]."&Msg=".$msg,1);
}

if( $Cmd=="Update")
{
		
		
		CheckRule($MenuId,$mydb,$TableName,"Update");//检查增加权限
   if(mb_strlen($_REQUEST[$TableName."1"])>4)
   {
   		$AdminFields[1]=$_REQUEST[$TableName."1"];
		if($_REQUEST[$TableName."2"]!="") $AdminFields[2]=md5($_REQUEST[$TableName."2"]);
		$AdminFields[3]=$_REQUEST[$TableName."3"];
		$AdminFields[4]=$_REQUEST[$TableName."4"];
		$AdminFields[5]=$_REQUEST[$TableName."5"];
		$AdminFields[7]=$_REQUEST[$TableName."7"];
		$MyAdminSys->UserName=$_REQUEST[$TableName."1"];
		$MyAdminSys->Info=$AdminFields;
		
		
		
			$mydb->TableName=$TableName;
			$AdminFields[0]=$CurrMenuId;
			$mydb->ArrFields=$AdminFields;
			$mydb->UpdateFieldIdlist="1,2,3,4,5,7";
			$mydb->Update();
			$msg="更新成功";
		
   }
   else
   {
   	 $msg="　　用户名不能少于5位！";
   }
   gourl("?MenuId=".$_REQUEST["MenuId"]."&Msg=".$msg,1);
}

?>

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户管理</title>
<link href="../../Inc/Css.css" rel="stylesheet" type="text/css" />

</head>

<body>
<p>

<?

 echo CurrPosition((int)($_REQUEST["MenuId"]),$mydb);?></p>


<?
$MenuId=$_REQUEST["MenuId"];

   ShowAdminList($MenuId,$mydb);
   echo $_REQUEST["Msg"]."";
?>

</body>
</html>



